package chartor;

import java.awt.Rectangle;

public abstract class Monster extends Rectangle {
	private float health;
	private int speed;
	private int atk;
	public float HEALTH = 100;
	private String nameString;
	private Player hitmanPlayer;
	private boolean cool;
	private Gun uGun;
	private int num;// 可以移动的次数

	public void move() {
		if(num>0) {
			for (int i = 0; i < speed; i++) {
				if (hitmanPlayer.x > this.x) {
					setX(x + 1);
				} else {
					setX(x - 1);
				}
				if (hitmanPlayer.y > this.y) {
					setY(y += 1);
				} else {
					setY(y -= 1);
				}
			}
			num--;
		}
	};

	public void beatk(Bullet bullet) {
		int dx = (this.x + width / 2 - bullet.x) / 2;
		int dy = (this.y + height / 2 - bullet.y) / 2;
		this.translate(dx, dy);
	}

	public void avoid(Rectangle monster) {
		if (monster.x > this.x) {
			this.x -= speed;
		} else if (monster.x == this.x) {

		} else if (monster.x > this.x) {
			this.x += speed;
		}
		if (monster.y > this.y) {
			this.y -= speed;
		} else if (monster.y < this.y) {
			this.y += speed;
		}
	}

	public void selectman() {
		int min = Integer.MAX_VALUE;
		for (Player s : Plas.players.values()) {
			if (s.getHealth() > 0) {
				int i = Math.abs(s.x - this.x) + Math.abs(s.y - this.y);
				if (i < min) {
					hitmanPlayer = s;
					min = i;
				}
			} else {
				continue;
			}
		}
	};

	public abstract void atkman(Player p);

	public abstract void reword(Player p);

	public Monster(int health, int speed, int atk, String nameString, Player hitmanPlayer, int x, int y, int w, int h) {
		super();
		this.health = health;
		this.speed = speed;
		this.atk = atk;
		this.nameString = nameString;
		this.hitmanPlayer = hitmanPlayer;
		this.x = x;
		this.y = y;
		this.width = w;
		this.height = h;
		this.cool = false;
		selectman();
	}
	public void mont() {
		num += 4;
	}

	public float getHealth() {
		return health;
	}
	public void setHealth(float health) {
		this.health = health;
	}

	public int getSpeed() {
		return speed;
	}

	public void setSpeed(int speed) {
		this.speed = speed;
	}

	public int getAtk() {
		return atk;
	}

	public void setAtk(int atk) {
		this.atk = atk;
	}

	public String getNameString() {
		return nameString;
	}

	public void setNameString(String nameString) {
		this.nameString = nameString;
	}

	public Player getHitmanPlayer() {
		return hitmanPlayer;
	}

	public void setHitmanPlayer(Player hitmanPlayer) {
		this.hitmanPlayer = hitmanPlayer;
	}

	public void setX(int x) {
		this.x = x;
	}

	public void setY(int y) {
		this.y = y;
	}

	public boolean isCool() {
		return cool;
	}

	public void setCool(boolean cool) {
		this.cool = cool;
	}

	public Gun getuGun() {
		return uGun;
	}

	public void setuGun(Gun uGun) {
		this.uGun = uGun;
	}
}
